package com.qidian.controller;

import com.qidian.pojo.StudentBase;
import com.qidian.service.StudentBaseService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import javax.annotation.Resource;

/**
 * (StudentBase)控制层
 *
 * @author 戴着假发的程序员
 * @since 2022-03-01 08:47:07
 */
@RestController
@RequestMapping("/studentBase")
public class StudentBaseController {
    /**
     * 服务对象
     */
    @Resource
    private StudentBaseService studentBaseService;

    /**
     * 通过主键查询单条数据
     *
     * @param studentBase 参数对象
     * @return 单条数据
     */
    @RequestMapping(value = "get", method = RequestMethod.GET)
    public StudentBase selectOne(StudentBase studentBase) {
        StudentBase result = studentBaseService.selectById(studentBase.getStudentId());
        if(result != null){
          return  result;
        }
        return null;
    }
    
    /**
     * 新增一条数据
     *
     * @param studentBase 实体类
     * @return Map
     */
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public Map insert(StudentBase studentBase) {
        Map map = new HashMap();
        map.put("code",200);
        int result = studentBaseService.insert(studentBase);
        if (result <= 0) {
          map.put("code",500);
        }
        return map;
    }

    /**
     * 修改一条数据
     *
     * @param studentBase 实体类
     * @return Response对象
     */
    @RequestMapping(value = "update")
    public Map update(StudentBase studentBase) {
        Map map = new HashMap();
        map.put("code",200);
        StudentBase result = studentBaseService.update(studentBase);
        if (result != null) {
            map.put("data",result);
        }else{
            map.put("code",500);
        }
        return map;
    }

    /**
     * 删除一条数据
     *
     * @param studentBase 参数对象
     * @return Response对象
     */
    @RequestMapping(value = "delete")
    public Map delete(StudentBase studentBase) {
        Map map = new HashMap();
        map.put("code",200);
        int result = studentBaseService.deleteById(studentBase.getStudentId());
        if (result <= 0) {
           map.put("code",500);
        }
        return map;
    }

     /**
     * 批量删除
     *
     * @param ids
     * @return Response对象
     */
    @RequestMapping(value = "deletes")
    public Map deletes(Long [] ids) {
        Map map = new HashMap();
        map.put("code",200);
        int result = studentBaseService.deleteByIds(ids);
        if (result <= 0) {
           map.put("code",500);
        }
        return map;
    }

    /**
     * 查询全部
     *
     * @return Response对象
     */
    @RequestMapping(value = "selectAll")
    public List<StudentBase> selectAll() {
        return studentBaseService.selectAll();
    }

    /**
     * 分页查询
     *
     * @param page 偏移
     * @param limit 条数
     * @return List<StudentBase>
     */
    @RequestMapping(value = "selectPage", method = RequestMethod.GET)
    public List<StudentBase> selectPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit) {
        return studentBaseService.selectPage(page, limit);
    }
    /**
     * 分页查询
     *
     * @param page 偏移
     * @param limit 条数
     * @return List<StudentBase>
     */
    @RequestMapping(value = "selectPageByPojo", method = RequestMethod.GET)
    public List<StudentBase> selectPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit,StudentBase studentBase) {
        return studentBaseService.selectPage(page, limit,studentBase);
    }

        /**
     * 分页查询
     *
     * @param page 偏移
     * @param limit 条数
     * @return Response对象
     */
    @RequestMapping(value = "selectPageForLayui")
    public Map selectPageForLayui(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit,StudentBase studentBase) {
        return studentBaseService.selectPageForLayui(page, limit,studentBase);
    }

    
}